package com.jiangyg.devtools.ui;

import com.intellij.lang.Language;
import com.intellij.openapi.editor.SpellCheckingEditorCustomizationProvider;
import com.intellij.openapi.project.Project;
import com.intellij.ui.*;
import com.intellij.util.containers.ContainerUtil;
import com.jiangyg.devtools.toolkit.Assert;

import java.util.HashSet;
import java.util.Set;

/**
 * 类描述：JSON 文本域编辑器
 *
 * @author jiangyg
 * @date 2023-08-17
 */
public class EditorTextAreaBuilder {

    private Project project;

    private final Set<EditorCustomization> features = new HashSet<>();

    private EditorTextAreaBuilder() {

    }

    public static EditorTextAreaBuilder instance() {
        return new EditorTextAreaBuilder();
    }

    public EditorTextAreaBuilder project(Project project) {
        this.project = project;
        return this;
    }

    public EditorTextAreaBuilder defaultFeatures() {
        ContainerUtil.addIfNotNull(features, SpellCheckingEditorCustomizationProvider.getInstance().getEnabledCustomization());
        features.add(SoftWrapsEditorCustomization.ENABLED);
        features.add(HorizontalScrollBarEditorCustomization.ENABLED);
        features.add(OneLineEditorCustomization.DISABLED);
        return this;
    }

    public EditorTextAreaBuilder add(EditorCustomization customization) {
        features.add(customization);
        return this;
    }

    public EditorTextField build(Language language) {
        Assert.notNull(project);
        Assert.notEmpty(features);

        return EditorTextFieldProvider.getInstance()
                .getEditorField(language, project, features);
    }

}
